<template>
    <div>
        <button @click="getStudents"> 获取学生信息</button>
        <button @click="getCars"> 获取汽车信息</button>
        <div>获取的内容：{{ resultValue }}</div>
    </div>
</template>
<script>
import axios from 'axios'
export default {
    name: 'UseAxios',
    data() {
        return {
            resultValue: '',
        }
    },
    methods: {
        getStudents() {
            ///Users/fengmac/Desktop/Desk/Net/尚硅谷/Vue2/资料（含课件）/05_其他/test_proxy_server 需要启动服务 node server1
            //如果用的是自己的mac 还要注意localhost的映射，使用switch软件更改相应的host配置
            axios.get('http://localhost:8080/stuApi/students').then(
                respoonse => {
                    console.log('请求成功', respoonse.data)
                    this.resultValue = respoonse.data
                },
                error => {
                    console.log('请求失败', error.message)
                    this.resultValue = error.message
                }
            )
        },
        getCars() {
            //需要启动服务 node server2
            axios.get('http://localhost:8080/carApi/cars').then(
                respoonse => {
                    console.log('请求成功', respoonse.data)
                    this.resultValue = respoonse.data
                },
                error => {
                    console.log('请求失败', error.message)
                    this.resultValue = error.message
                }
            )
        }
    }
}
</script>